<template>
	<view class="page-login">
		<image mode="heightFix" class="logo-img" src="/static/logo-color.png" />
		<uni-easyinput class="input-id" v-model="screenId" placeholder="请输入屏幕ID" confirm-type="go" @confirm="login" />
		<view>版本号：{{version}}</view>
	</view>

</template>

<script>
	import OfflineData from '/common/offline-data-cache.js'
	import {
		baseUrl, version
	} from '@/common/config.js'
	export default {
		data() {
			return {
				screenId: '',
				windowInfo: {},
				loading: false,
				version
			}
		},
		computed: {
			// version() {
			// 	// #ifdef APP
			// 	return plus.runtime.versionCode
			// 	// #endif
			// 	// #ifdef H5
			// 	return 0
			// 	// #endif
			// },
		},
		async mounted() {

			const savedScreenId = uni.getStorageSync('screenId');
			if (savedScreenId) {
				uni.showToast({
					title: '已登录, ID=' + savedScreenId,
					duration: 3000
				});
				this.screenId = savedScreenId;
				// 更新数据
				try{
					await OfflineData.updateOfflineData(this.screenId);
					this.goToIndex()
				}catch(e){
					console.error(e)
					this.goToIndex()
				}
			} else {
				uni.showToast({
					title: '未登录'
				})
			}


		},
		methods: {
			async login() {
				uni.showToast({
					title: '使用' + this.screenId + '登录'
				})
				// 更新数据
				await OfflineData.updateOfflineData(this.screenId);
				uni.setStorage({
					key: 'screenId',
					data: this.screenId,
				})
				this.goToIndex()
			},
			goToIndex() {
				uni.navigateTo({
					url: '/pages/index/index'
				})
			},
			
		}
	}
</script>

<style scoped>
	.page-login {
		width: 100%;
		height: 100vh;
		background-color: #F3F3F8;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.logo-img {
		margin-top: 20vh;
		height: 400rpx;
	}

	.input-id {
		width: 400rpx;
		text-align: center;
	}
</style>